package com.lixh.sdk.base.http


import com.lixh.sdk.base.BaseApplication.Companion.appContext
import okhttp3.Cache
import okhttp3.OkHttpClient.Builder
import java.io.File
import java.util.concurrent.TimeUnit

object ClientFactory {
    private const val TIMEOUT_CONNECTION: Long = 30L
    private const val TIMEOUT_READ: Long = 30L


    fun client(): Builder = Builder().apply {
        sslSocketFactory(ClientHelper.sslSocketFactory, ClientHelper.trustManager)
        hostnameVerifier { _, _ -> true }
        val cacheFile = File(appContext.cacheDir, "cache")
        val cache = Cache(cacheFile, (10 * 1024 * 1024).toLong())
        addNetworkInterceptor(ClientHelper.AutoCacheInterceptor())
        cache(cache)
        retryOnConnectionFailure(true)
            .readTimeout(TIMEOUT_READ, TimeUnit.SECONDS)
            .connectTimeout(TIMEOUT_CONNECTION, TimeUnit.SECONDS)
            .build()
    }

}